package com.zrwl.poscloud.core.restapi.message;


import com.zrwl.poscloud.base.entity.MessageModel;
import com.zrwl.poscloud.commons.vo.message.SmsVO;
import com.zrwl.poscloud.xo.service.MessageModelService;
import com.zrwl.poscloud.xo.service.SmsService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 角色表 RestApi
 *
 * @author liusitong
 * @date 2018-09-04
 */
@RestController
@RequestMapping("/sms")
@Slf4j
public class SmsRestApi {

    @Autowired
    private SmsService smsService;
    @Autowired
    MessageModelService messageModelService;

    @RequestMapping("/queryAccount")
    public String queryAccount() throws Exception {
        return smsService.queryAccount();
    }
    @ApiOperation(value = "发送短信", notes = "发送短信", response = String.class)
    @RequestMapping("/sendSMSMessage")
    public String sendSMSMessage(@RequestParam("telephone")String telephone, @RequestParam("type")int type, @RequestParam("content")String content) throws Exception {
        MessageModel model = messageModelService.getConfig(1, type);
        if(model == null){
            return "未配置对应的消息模板";
        }
        //发送模板消息
        SmsVO smsVO = smsService.send(telephone,model.getCode(), content);
        if (smsVO.isRequestSuccess() && smsVO.isSendSuccess()) {
            return "true";
        } else {
            return "false";
        }
    }
}